from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-03 14:06:16.837117
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 03, Feb, 2022
Time: 14:06:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9617
Nobs: 556.000 HQIC: -48.3879
Log likelihood: 6517.41 FPE: 7.35832e-22
AIC: -48.6611 Det(Omega_mle): 6.26764e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350832 0.069598 5.041 0.000
L1.Burgenland 0.105962 0.042244 2.508 0.012
L1.Kärnten -0.110560 0.021958 -5.035 0.000
L1.Niederösterreich 0.193191 0.088342 2.187 0.029
L1.Oberösterreich 0.132190 0.087313 1.514 0.130
L1.Salzburg 0.254382 0.044676 5.694 0.000
L1.Steiermark 0.035043 0.058899 0.595 0.552
L1.Tirol 0.098930 0.047552 2.080 0.037
L1.Vorarlberg -0.070974 0.042032 -1.689 0.091
L1.Wien 0.018410 0.077712 0.237 0.813
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054251 0.150542 0.360 0.719
L1.Burgenland -0.041652 0.091375 -0.456 0.649
L1.Kärnten 0.040520 0.047496 0.853 0.394
L1.Niederösterreich -0.203299 0.191087 -1.064 0.287
L1.Oberösterreich 0.454546 0.188860 2.407 0.016
L1.Salzburg 0.283605 0.096636 2.935 0.003
L1.Steiermark 0.115256 0.127400 0.905 0.366
L1.Tirol 0.306083 0.102857 2.976 0.003
L1.Vorarlberg 0.023397 0.090916 0.257 0.797
L1.Wien -0.023228 0.168094 -0.138 0.890
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196124 0.035400 5.540 0.000
L1.Burgenland 0.090597 0.021487 4.216 0.000
L1.Kärnten -0.007345 0.011169 -0.658 0.511
L1.Niederösterreich 0.234165 0.044934 5.211 0.000
L1.Oberösterreich 0.168369 0.044411 3.791 0.000
L1.Salzburg 0.038612 0.022724 1.699 0.089
L1.Steiermark 0.025463 0.029958 0.850 0.395
L1.Tirol 0.081277 0.024187 3.360 0.001
L1.Vorarlberg 0.055806 0.021379 2.610 0.009
L1.Wien 0.118661 0.039528 3.002 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118990 0.035522 3.350 0.001
L1.Burgenland 0.043144 0.021561 2.001 0.045
L1.Kärnten -0.013757 0.011207 -1.228 0.220
L1.Niederösterreich 0.170071 0.045090 3.772 0.000
L1.Oberösterreich 0.335148 0.044564 7.521 0.000
L1.Salzburg 0.099911 0.022803 4.382 0.000
L1.Steiermark 0.109253 0.030062 3.634 0.000
L1.Tirol 0.090946 0.024271 3.747 0.000
L1.Vorarlberg 0.061148 0.021453 2.850 0.004
L1.Wien -0.015141 0.039664 -0.382 0.703
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126626 0.066963 1.891 0.059
L1.Burgenland -0.048860 0.040645 -1.202 0.229
L1.Kärnten -0.045473 0.021127 -2.152 0.031
L1.Niederösterreich 0.139332 0.084998 1.639 0.101
L1.Oberösterreich 0.165931 0.084008 1.975 0.048
L1.Salzburg 0.284292 0.042985 6.614 0.000
L1.Steiermark 0.057552 0.056669 1.016 0.310
L1.Tirol 0.156182 0.045752 3.414 0.001
L1.Vorarlberg 0.094589 0.040441 2.339 0.019
L1.Wien 0.073159 0.074771 0.978 0.328
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080728 0.052250 1.545 0.122
L1.Burgenland 0.024355 0.031714 0.768 0.443
L1.Kärnten 0.053403 0.016485 3.240 0.001
L1.Niederösterreich 0.190570 0.066322 2.873 0.004
L1.Oberösterreich 0.331091 0.065549 5.051 0.000
L1.Salzburg 0.033006 0.033540 0.984 0.325
L1.Steiermark 0.004522 0.044218 0.102 0.919
L1.Tirol 0.119582 0.035699 3.350 0.001
L1.Vorarlberg 0.066439 0.031555 2.106 0.035
L1.Wien 0.098268 0.058342 1.684 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174410 0.063143 2.762 0.006
L1.Burgenland 0.002280 0.038326 0.059 0.953
L1.Kärnten -0.065517 0.019921 -3.289 0.001
L1.Niederösterreich -0.110510 0.080149 -1.379 0.168
L1.Oberösterreich 0.213401 0.079215 2.694 0.007
L1.Salzburg 0.053648 0.040533 1.324 0.186
L1.Steiermark 0.248400 0.053436 4.649 0.000
L1.Tirol 0.499350 0.043142 11.575 0.000
L1.Vorarlberg 0.065371 0.038133 1.714 0.086
L1.Wien -0.077381 0.070505 -1.098 0.272
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157213 0.069847 2.251 0.024
L1.Burgenland -0.004928 0.042395 -0.116 0.907
L1.Kärnten 0.062176 0.022037 2.822 0.005
L1.Niederösterreich 0.180191 0.088659 2.032 0.042
L1.Oberösterreich -0.067050 0.087625 -0.765 0.444
L1.Salzburg 0.205518 0.044836 4.584 0.000
L1.Steiermark 0.138734 0.059110 2.347 0.019
L1.Tirol 0.056978 0.047723 1.194 0.233
L1.Vorarlberg 0.143466 0.042182 3.401 0.001
L1.Wien 0.131005 0.077991 1.680 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.396232 0.040795 9.713 0.000
L1.Burgenland -0.003660 0.024762 -0.148 0.883
L1.Kärnten -0.020662 0.012871 -1.605 0.108
L1.Niederösterreich 0.200919 0.051782 3.880 0.000
L1.Oberösterreich 0.239779 0.051179 4.685 0.000
L1.Salzburg 0.034123 0.026187 1.303 0.193
L1.Steiermark -0.019054 0.034524 -0.552 0.581
L1.Tirol 0.088041 0.027873 3.159 0.002
L1.Vorarlberg 0.051606 0.024637 2.095 0.036
L1.Wien 0.036158 0.045551 0.794 0.427
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035072 0.106205 0.169285 0.134489 0.096217 0.081843 0.030529 0.213171
Kärnten 0.035072 1.000000 -0.025468 0.133116 0.046853 0.085815 0.444483 -0.068296 0.093254
Niederösterreich 0.106205 -0.025468 1.000000 0.312196 0.125855 0.270002 0.068063 0.157348 0.282806
Oberösterreich 0.169285 0.133116 0.312196 1.000000 0.215876 0.294302 0.170646 0.134960 0.237528
Salzburg 0.134489 0.046853 0.125855 0.215876 1.000000 0.124705 0.090363 0.104227 0.128738
Steiermark 0.096217 0.085815 0.270002 0.294302 0.124705 1.000000 0.133799 0.105874 0.029827
Tirol 0.081843 0.444483 0.068063 0.170646 0.090363 0.133799 1.000000 0.064223 0.152899
Vorarlberg 0.030529 -0.068296 0.157348 0.134960 0.104227 0.105874 0.064223 1.000000 -0.003719
Wien 0.213171 0.093254 0.282806 0.237528 0.128738 0.029827 0.152899 -0.003719 1.000000